package com.ct.application.shipping.service.impl;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.support.ExcelTypeEnum;
import com.ct.application.shipping.model.po.ChuanYuanKuExcelPO;
import com.ct.application.shipping.service.ChuanYuanFenZuService;
import com.ct.application.shipping.service.ChuanYuanKuDaoRuService;
import com.ct.application.shipping.service.ChuanYuanKuService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.io.InputStream;

/**
 * <p>
 * 船员库 服务实现类
 * </p>
 *
 * @author carlo
 */
@Service
public class ChuanYuanKuDaoRuServiceImpl implements ChuanYuanKuDaoRuService {

    @Resource
    private ChuanYuanFenZuService chuanYuanFenZuService;
    @Resource
    private ChuanYuanKuService chuanYuanKuService;

    public void chuanYuanDaoRu(InputStream inputStream,String fileType){
        ChuanYuanDaoRuListener listener = new ChuanYuanDaoRuListener(chuanYuanKuService,chuanYuanFenZuService);
        try {
            if (".xls".equalsIgnoreCase(fileType)) {
                EasyExcel.read(inputStream, ChuanYuanKuExcelPO.class, listener).excelType(ExcelTypeEnum.XLS).sheet().doRead();
            } else if (ExcelTypeEnum.CSV.getValue().equalsIgnoreCase(fileType)) {
                EasyExcel.read(inputStream, ChuanYuanKuExcelPO.class, listener).excelType(ExcelTypeEnum.CSV).sheet().doRead();
            } else {
                EasyExcel.read(inputStream, ChuanYuanKuExcelPO.class, listener).sheet().doRead();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
